<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>vsftp部署和优化 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>vsftp部署和优化</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/FTP/">FTP</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;作为系统默认自带的 ftp 服务软件，vsftp 也是比较常用的。</p>
<h2 id="1-安装-vsftp"><a href="#1-安装-vsftp" class="headerlink" title="1.安装 vsftp"></a>1.安装 vsftp</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># yum install -y vsftpd db4-utils</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这里安装两个软件包，同时会把依赖的包安装上。其中 db4-utils 用来生成木马库文件。</p>
<h2 id="2-建立帐号"><a href="#2-建立帐号" class="headerlink" title="2.建立帐号"></a>2.建立帐号</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;vsftp 默认是可以支持使用系统帐号体系登录的，但这样不太安全，所以建议使用虚拟账号体系。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;建立虚拟账号相关的系统帐号</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># useradd virftp -s /sbin/nologin</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;建立虚拟账户相关的文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># vim /etc/vsftpd/vsftpd_login</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">test1</div><div class="line">123456</div><div class="line">test2</div><div class="line">abcdef</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;更改该文件的权限，提升安全级别</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># chmod 600 /etc/vsftpd/vsftpd_login</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;vsftpd 使用的密码文件肯定不是铭文的，需要生成对应的库文件：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># db_load -T -t hash -f /etc/vsftpd/vsftpd_login /etc/vsftpd/vsftpd_login.db</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;建立虚拟帐号相关的目录以及配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 ~]<span class="comment"># mkdir /etc/vsftpd/vsftpd_user_conf</span></div><div class="line">[root@192 ~]<span class="comment"># cd /etc/vsftpd/vsftpd_user_conf</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;3.创建和用户对应的配置文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># vim test1</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">local_root=/home/virftp/test1</div><div class="line">anonymous_enable=NO</div><div class="line">write_enable=YES</div><div class="line">local_umask=022</div><div class="line">anon_upload_enable=NO</div><div class="line">anon_mkdir_write_enable=NO</div><div class="line">idle_session_timeout=600</div><div class="line">data_connection_timeout=120</div><div class="line">max_clients=10</div><div class="line">max_per_ip=5</div><div class="line">local_max_rate=50000</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明:local_root 为该帐号的家目录，anonymous_enable 用来限制是否允许匿名帐号登录，若为 NO 表示不允许匿名帐号登录， write_enable=YES 表示可写，local_umask 指定 umask 值，anon_upload_enable 是否允许匿名帐号上传文件，anon_mkdir_write_enable 是否允许匿名帐号可写。以上为关键参数，其他暂时不用关心，创建 test2 帐号的步骤和 test1 一样。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># mkdir /home/virftp/test1</span></div><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># chown -R virftp:virftp /home/virftp</span></div><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># vim /etc/pam.d/vsftpd</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在最开头添加两行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login</div><div class="line">account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;说明：linux 为 64 位系统，所以库文件为 /lib64/security/pam_userdb.so ，若系统为 32位，那么库文件在 /lib/security/pam_userdb.so</p>
<h2 id="4-修改全局配置文件-etc-vsftpd-conf"><a href="#4-修改全局配置文件-etc-vsftpd-conf" class="headerlink" title="4.修改全局配置文件 /etc/vsftpd.conf"></a>4.修改全局配置文件 /etc/vsftpd.conf</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># vim /etc/vsftpd/vsftpd.conf</span></div></pre></td></tr></table></figure>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/01.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/02.png?raw=true" alt=""></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/03.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/04.png?raw=true" alt=""></figure></p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/05.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;改为</p>
<p><figure class="figure"><img src="https://github.com/hcldirgit/image/blob/master/vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/06.png?raw=true" alt=""></figure></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;再增加：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">chroot_local_user=YES</div><div class="line">guest_enabled=YES</div><div class="line">guest_username=virftp</div><div class="line">virtual_use_local_privs=YES</div><div class="line">user_config_dir=/etc/vsftpd/vsftpd_user_conf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最后启动 vsftpd 服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@192 vsftpd_user_conf]<span class="comment"># /etc/init.d/vsftpd start </span></div><div class="line">为 vsftpd 启动 vsftpd： [确定]</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果服务启动不了，很有可能是前面 21端口占用。测试过程和 pure-ftpd 一样，如果用户无法登录，查看日志 /var/log/srcure</p>

	

	
		<span class="different-posts"><a href="/2017/10/12/FTP/2. vsftp部署和优化/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
